package com.lmiot.xyclick.Activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.SQL.AutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.Util.DataUtil;
import com.yanzhenjie.recyclerview.swipe.SwipeMenu;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuBridge;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuItem;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuItemClickListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
import com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener;
import com.yanzhenjie.recyclerview.swipe.touch.OnItemStateChangedListener;
import com.yanzhenjie.recyclerview.swipe.widget.DefaultItemDecoration;
import com.youyi.yyviewsdklibrary.View.TitleBarView;
import java.util.Collections;
import java.util.List;

public class SortAutoListActivity extends BaseActivity {
    private SortAutoAdapter mAutoAdapter;
    TitleBarView mIdTitleBar;
    private LinearLayoutManager mLayoutManager;
    SwipeMenuRecyclerView mRecyclerView;

    /* access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.SupportActivity, android.support.v4.app.FragmentActivity, com.lmiot.xyclick.Activity.BaseActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_sort_list);
        initView();
        setTitle();
        setDrag();
    }

    private void setTitle() {
        this.mIdTitleBar.setOnItemClickListener(new TitleBarView.onItemClickListener() {
            /* class com.lmiot.xyclick.Activity.SortAutoListActivity.AnonymousClass1 */

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onMenuClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onTitleClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onBackClick(View view) {
                SortAutoListActivity.this.finish();
            }
        });
    }

    private void setDrag() {
        this.mRecyclerView.addItemDecoration(new DefaultItemDecoration(getResources().getColor(R.color.transparent), -1, 20, 99));
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, 1, false);
        this.mLayoutManager = linearLayoutManager;
        this.mRecyclerView.setLayoutManager(linearLayoutManager);
        this.mRecyclerView.setFocusable(false);
        new SwipeMenuCreator() {
            /* class com.lmiot.xyclick.Activity.SortAutoListActivity.AnonymousClass2 */

            @Override // com.yanzhenjie.recyclerview.swipe.SwipeMenuCreator
            public void onCreateMenu(SwipeMenu swipeMenu, SwipeMenu swipeMenu2, int i) {
                SwipeMenuItem swipeMenuItem = new SwipeMenuItem(SortAutoListActivity.this);
                swipeMenuItem.setText(R.string.rm);
                swipeMenuItem.setWidth(120);
                swipeMenuItem.setBackgroundColor(SortAutoListActivity.this.getResources().getColor(R.color.colorAccent));
                swipeMenuItem.setHeight(-1);
                swipeMenuItem.setTextColor(-1);
                swipeMenu2.addMenuItem(swipeMenuItem);
            }
        };
        SwipeMenuItemClickListener r0 = new SwipeMenuItemClickListener() {
            /* class com.lmiot.xyclick.Activity.SortAutoListActivity.AnonymousClass3 */

            @Override // com.yanzhenjie.recyclerview.swipe.SwipeMenuItemClickListener
            public void onItemClick(SwipeMenuBridge swipeMenuBridge) {
                swipeMenuBridge.closeMenu();
                swipeMenuBridge.getDirection();
                swipeMenuBridge.getAdapterPosition();
                swipeMenuBridge.getPosition();
            }
        };
        this.mRecyclerView.setItemViewSwipeEnabled(false);
        this.mRecyclerView.setLongPressDragEnabled(true);
        this.mRecyclerView.setSwipeMenuItemClickListener(r0);
        OnItemMoveListener r02 = new OnItemMoveListener() {
            /* class com.lmiot.xyclick.Activity.SortAutoListActivity.AnonymousClass4 */

            @Override // com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener
            public boolean onItemMove(RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder viewHolder2) {
                SortAutoListActivity.this.mAutoAdapter.sortData(viewHolder.getAdapterPosition(), viewHolder2.getAdapterPosition());
                return true;
            }

            @Override // com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener
            public void onItemDismiss(RecyclerView.ViewHolder viewHolder) {
                viewHolder.getAdapterPosition();
            }
        };
        this.mRecyclerView.setLongPressDragEnabled(true);
        this.mRecyclerView.setOnItemMoveListener(r02);
        this.mRecyclerView.setOnItemStateChangedListener(new OnItemStateChangedListener() {
            /* class com.lmiot.xyclick.Activity.SortAutoListActivity.AnonymousClass5 */

            @Override // com.yanzhenjie.recyclerview.swipe.touch.OnItemStateChangedListener
            public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int i) {
                if (i == 0) {
                    viewHolder.itemView.setAlpha(1.0f);
                    viewHolder.itemView.findViewById(R.id.id_main).setBackgroundResource(R.drawable.whitebg_5dp);
                    AutoBeanSqlUtil.getInstance().addList(SortAutoListActivity.this.mAutoAdapter.getList());
                } else if (i == 2) {
                    viewHolder.itemView.setAlpha(0.5f);
                    viewHolder.itemView.findViewById(R.id.id_main).setBackgroundResource(R.drawable.color_bg_red);
                }
            }
        });
    }

    @Override // android.support.v4.app.FragmentActivity, com.lmiot.xyclick.Activity.BaseActivity
    public void onResume() {
        super.onResume();
        showListView();
    }

    public void showListView() {
        SortAutoAdapter sortAutoAdapter = new SortAutoAdapter(AutoBeanSqlUtil.getInstance().searchAll());
        this.mAutoAdapter = sortAutoAdapter;
        this.mRecyclerView.setAdapter(sortAutoAdapter);
        this.mRecyclerView.setNestedScrollingEnabled(false);
    }

    private void initView() {
        this.mIdTitleBar = (TitleBarView) findViewById(R.id.id_title_bar);
        this.mRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recyclerView);
    }

    public class SortAutoAdapter extends RecyclerView.Adapter {
        private List<AutoBean> mList;

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public int getItemViewType(int i) {
            return 0;
        }

        public SortAutoAdapter(List<AutoBean> list) {
            this.mList = list;
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            return new AutoViewHolder(View.inflate(SortAutoListActivity.this, R.layout.item_sort_auto, null));
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
            String str;
            final AutoViewHolder autoViewHolder = (AutoViewHolder) viewHolder;
            final AutoBean autoBean = this.mList.get(i);
            int i2 = i % 5;
            int i3 = 1;
            if (i2 == 4) {
                autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_other);
            } else if (i2 == 3) {
                autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_play);
            } else if (i2 == 2) {
                autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_time);
            } else if (i2 == 1) {
                autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_screen);
            } else {
                autoViewHolder.bg.setBackgroundResource(R.drawable.auto_color_text);
            }
            if (DataUtil.getShowAuto(MyApp.getInstance(), autoBean.getAutoID())) {
                autoViewHolder.checked.setVisibility(View.VISIBLE);
                autoViewHolder.unchecked.setVisibility(View.GONE);
                autoViewHolder.itemView.setAlpha(1.0f);
            } else {
                autoViewHolder.checked.setVisibility(View.GONE);
                autoViewHolder.unchecked.setVisibility(View.VISIBLE);
                autoViewHolder.itemView.setAlpha(0.3f);
            }
            autoViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Activity.SortAutoListActivity.SortAutoAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    if (DataUtil.getShowAuto(MyApp.getInstance(), autoBean.getAutoID())) {
                        DataUtil.setShowAuto(MyApp.getInstance(), autoBean.getAutoID(), false);
                        autoViewHolder.checked.setVisibility(View.GONE);
                        autoViewHolder.unchecked.setVisibility(View.VISIBLE);
                        autoViewHolder.itemView.setAlpha(0.3f);
                        return;
                    }
                    DataUtil.setShowAuto(MyApp.getInstance(), autoBean.getAutoID(), true);
                    autoViewHolder.checked.setVisibility(View.VISIBLE);
                    autoViewHolder.unchecked.setVisibility(View.GONE);
                    autoViewHolder.itemView.setAlpha(1.0f);
                }
            });
            autoViewHolder.name.setText(autoBean.getAutoName());
            int repeatNum = autoBean.getRepeatNum();
            if (repeatNum != 0) {
                i3 = repeatNum;
            }
            TextView textView = autoViewHolder.repeat;
            StringBuilder sb = new StringBuilder();
            sb.append(SortAutoListActivity.this.getString(R.string.r_tt));
            if (i3 == -1) {
                str = SortAutoListActivity.this.getString(R.string.wx);
            } else {
                str = i3 + "";
            }
            sb.append(str);
            sb.append(SortAutoListActivity.this.getString(R.string.ts));
            textView.setText(sb.toString());
            autoViewHolder.time.setText(SortAutoListActivity.this.getString(R.string.cr_t) + autoBean.getCreateTime());
        }

        public List<AutoBean> getList() {
            return this.mList;
        }

        @Override // android.support.v7.widget.RecyclerView.Adapter
        public int getItemCount() {
            List<AutoBean> list = this.mList;
            if (list == null) {
                return 0;
            }
            return list.size();
        }

        public void sortData(int i, int i2) {
            try {
                Collections.swap(this.mList, i, i2);
                notifyItemMoved(i, i2);
                for (int i3 = 0; i3 < this.mList.size(); i3++) {
                    this.mList.get(i3).setSortNum((this.mList.size() + 1) - i3);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        private class AutoViewHolder extends RecyclerView.ViewHolder {
            ImageView bg;
            ImageView checked;
            TextView name;
            TextView repeat;
            TextView time;
            ImageView unchecked;

            public AutoViewHolder(View view) {
                super(view);
                this.bg = (ImageView) view.findViewById(R.id.cb_bg);
                this.checked = (ImageView) view.findViewById(R.id.checked);
                this.unchecked = (ImageView) view.findViewById(R.id.unchecked);
                this.name = (TextView) view.findViewById(R.id.id_name);
                this.repeat = (TextView) view.findViewById(R.id.id_repeat);
                this.time = (TextView) view.findViewById(R.id.id_time);
            }
        }
    }
}
